<template>
  <view class="page">
    <view class="header">公交线路查询</view>
    <view class="busList">
      <view
        class="list"
        v-for="(item, index) in busList"
        :key="index"
        @tap="toBusDetail(index)"
      >
        <view class="title">{{ item.path }}</view>
        <view class="upName">起始站名 {{ item.upName }}</view>
        <view class="downName">终点站站名 {{ item.downName }}</view>
      </view>
    </view>
  </view>
</template>

<script>
import "./busList.scss";
import Taro from "@tarojs/taro";
export default {
  data() {
    return {
      msg: "Hello world!",
      //   线路信息
      busList: [],
    };
  },
  created() {
    this.getBusList();
  },
  methods: {
    getBusList() {
      let that = this;
      Taro.request({
        url: "http://localhost:8080/busList",
        method: "get",
        success: function (res) {
          that.busList = res.data.data;
          console.log(that.busList);
          Taro.setStorage({
            key: "busList",
            data: res.data.data,
          });
        },
      });
    },
    // 跳转详情
    toBusDetail(index) {
      console.log(index);
      Taro.reLaunch({
        url: "../../pages/busDetails/busDetails?id=" + index,
      });
    },
  },
};
</script>
